//
//  JSSEmoticonPopButton.swift
//  WeiBoItem
//
//  Created by jss on 16/5/1.
//  Copyright © 2016年 jss. All rights reserved.
//

import UIKit

class JSSEmoticonPopButton: UIButton {

    
    //当前表情按钮对应的表情模型
    var emoticon:JSSEmoticonModel?{
    
        didSet{
            
            guard let _ = emoticon else {
                
                return
            }
        
        //判断是Emoji表情还是图片表情
            if emoticon?.type == "1" {
            //代表时候emoji表情
                self.setTitle((emoticon!.code! as NSString).emoji(), forState: UIControlState.Normal)
                
                //因为复用 所以设置Emoji表情的时候把图片设置为nil
                self.setImage(nil, forState: UIControlState.Normal)
                
            }else {
            
                //代表是图片表情
                //读取图片
                let image = UIImage(named: "\(emoticon?.folderName ?? "")/\(emoticon?.png ?? "")", inBundle: JSSEmoticonkeyboardViewModel.EmoticonkeyboardSharedViewModel.emoticonBundle, compatibleWithTraitCollection: nil)
                self.setImage(image, forState: UIControlState.Normal)
                
                //同时 把文字设置成nil
                self.setTitle(nil, forState: UIControlState.Normal)
            
            }
        
        }
      
    }
}
            
